/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.seagate.app.manager;

import com.seagate.util.db.OracleConnectionPool;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author 452530
 */
public class LimitManager {

    public int getLimit() {

        String sql = "SELECT LIMIT FROM AMA_STDPART_LIMIT ";
        Connection conn = null;
        Statement stmt = null;
        ResultSet rset = null;
        try {
            conn = OracleConnectionPool.getConnection();
            stmt = conn.createStatement();
            rset = stmt.executeQuery(sql);
            while (rset.next() == true) {



               return rset.getInt("LIMIT");


            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rset.close();
                stmt.close();
                conn.close();
            } catch (SQLException ex) {
            }
        }

        return 0;
    }
    public int getLimit2() {

        String sql = "SELECT LIMIT2 FROM AMA_STDPART_LIMIT ";
        Connection conn = null;
        Statement stmt = null;
        ResultSet rset = null;
        try {
            conn = OracleConnectionPool.getConnection();
            stmt = conn.createStatement();
            rset = stmt.executeQuery(sql);
            while (rset.next() == true) {



               return rset.getInt("LIMIT2");


            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rset.close();
                stmt.close();
                conn.close();
            } catch (SQLException ex) {
            }
        }

        return 0;
    }
    public boolean editLimit(String limit,String limit2) {
        boolean result = false;
        String sql = "";
          sql = "update AMA_STDPART_LIMIT set LIMIT = '" + limit + "',LIMIT2 = '" + limit2 + "'  where ID = 1";


        Connection conn = null;
        Statement stmt = null;

        try {
            conn = OracleConnectionPool.getConnection();
            stmt = conn.createStatement();

            stmt.executeUpdate(sql);
            result = true;

        } catch (SQLException e) {
            System.err.println("sql = " + sql);
            System.err.println("code = " + e.getLocalizedMessage());
            result = false;
        } finally {
            try {
                stmt.close();
                conn.close();
            } catch (SQLException ex) {
            }
        }

        return result;
    }
}
